package com.xiaoxin.yixinai.companyversion;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.xiaoxin.yixinai._frame.utils.StringUtils;

/**
 * 公司版本接收参数类
 * @author lilipo
 *
 */
public class CompanyVersionParam {
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	
	/**
	 * 主键
	 */
	private Integer cvId;
	
	/**
	 * 结束时间
	 */
	private String endTimeStr;
	
	/**
	 * 版本主键
	 */
	private Integer versionId;
	
	/**
	 * 时长类型
	 */
	private String versionDurationType;
	
	/**
	 * 时长
	 */
	private Integer versionDuration;
	
	/**
	 * 转换成CompanyVersion类
	 * @return
	 */
	public CompanyVersion toCompanyVersion() {
		CompanyVersion companyVersion = new CompanyVersion();
		companyVersion.setId(this.cvId);
		companyVersion.setVersionId(this.versionId);
		if ("DURATION_MONTH".equals(this.versionDurationType) && this.versionDuration != null) {
			companyVersion.setDurationMonth(this.versionDuration);
		}
		if ("DURATION_DAY".equals(this.versionDurationType) && this.versionDuration != null) {
			companyVersion.setDurationDay(this.versionDuration);
		}
		
		try {
			if (StringUtils.isNotEmpty(this.endTimeStr)) {
				Date endTime = sdf.parse(this.endTimeStr);
				companyVersion.setEndTime(endTime);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return companyVersion;
	}
	
	/**
	 * 构造器
	 * @param versionId
	 * @param versionDurationType
	 * @param versionDuration
	 */
	public CompanyVersionParam(Integer versionId, String versionDurationType, Integer versionDuration) {
		super();
		this.versionId = versionId;
		this.versionDurationType = versionDurationType;
		this.versionDuration = versionDuration;
	}
	
	/**
	 * 构造器
	 * @param cvId
	 * @param endTimeStr
	 */
	public CompanyVersionParam(Integer cvId, String endTimeStr) {
		super();
		this.cvId = cvId;
		this.endTimeStr = endTimeStr;
	}

	public Integer getCvId() {
		return cvId;
	}

	public void setCvId(Integer cvId) {
		this.cvId = cvId;
	}

	public String getEndTimeStr() {
		return endTimeStr;
	}

	public void setEndTimeStr(String endTimeStr) {
		this.endTimeStr = endTimeStr;
	}

	public Integer getVersionId() {
		return versionId;
	}
	
	public void setVersionId(Integer versionId) {
		this.versionId = versionId;
	}
	
	public String getVersionDurationType() {
		return versionDurationType;
	}
	
	public void setVersionDurationType(String versionDurationType) {
		this.versionDurationType = versionDurationType;
	}
	
	public Integer getVersionDuration() {
		return versionDuration;
	}
	
	public void setVersionDuration(Integer versionDuration) {
		this.versionDuration = versionDuration;
	}
}
